package com.xingdata.jjxc.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xingdata.jjxc.R;
import com.xingdata.jjxc.activity.CarInfoListViewActivity;
import com.xingdata.jjxc.enty.CarInfoEntity;
import com.xingdata.jjxc.views.CircleImageView;

/**
 * 爱车列表adapter
 * 
 * @author ysc
 * 
 */
public class CarInfoListViewAdapter extends BaseAdapter {
	private Context context;
	private List<CarInfoEntity> carlistEntityList;
	private CarInfoEntity carlistEntity;
	private LayoutInflater inflater;

	public CarInfoListViewAdapter(Activity carlistActivity, List<CarInfoEntity> carlistEntityList) {
		this.context = carlistActivity;
		this.carlistEntityList = carlistEntityList;
	}

	@Override
	public int getCount() {
		return carlistEntityList == null ? 0 : carlistEntityList.size();
	}

	@Override
	public CarInfoEntity getItem(int position) {
		return carlistEntityList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.carlist, null);
			holder.carlistimage = (CircleImageView) convertView.findViewById(R.id.carlistimage);
			holder.carNumber = (TextView) convertView.findViewById(R.id.carlistnickname);
			holder.carFrameNumber = (TextView) convertView.findViewById(R.id.carlistcarnumber);
			holder.carEngineNumber = (TextView) convertView.findViewById(R.id.engineID);
			holder.carlistsmall_iv = (ImageView) convertView.findViewById(R.id.carlistsmall_iv);
			holder.car_brand = (TextView) convertView.findViewById(R.id.car_brand);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		Bitmap bitmap = BitmapFactory.decodeFile(carlistEntityList.get(position).getCar_branch_logo());
		holder.carlistimage.setImageBitmap(bitmap);
		
		holder.carNumber.setText(carlistEntityList.get(position).getCar_license_no());
		holder.car_brand.setText(carlistEntityList.get(position).getCar_branch_name());
		holder.carFrameNumber.setText(carlistEntityList.get(position).getCar_vin_no());
		holder.carEngineNumber.setText(carlistEntityList.get(position).getCar_engine_no());
		
		holder.car_id = carlistEntityList.get(position).getCar_id();
		holder.hud_sn = carlistEntityList.get(position).getHud_sn();

		// Bitmap bitmap =
		// BitmapFactory.decodeFile(carlistEntities.get(position).getCar_branch_logo());
		// holder.carlistimage.setImageBitmap(bitmap);
		// holder.carNumber.setText(carlistEntities.get(position).getCar_license_no());
		// holder.carBrand.setText(carlistEntities.get(position).getCar_branch_name());
		// holder.carFrameNumber.setText(carlistEntities.get(position).getCar_vin_no());
		// holder.carEngineNumber.setText(carlistEntities.get(position).getCar_engine_no());
		// holder.car_id=carlistEntities.get(position).getCar_id();
		// holder.hud_sn=carlistEntities.get(position).getHud_sn();

		// carlistEntity = carlistEntities.get(position);
		// holder.carlistimage.setImageResource(R.drawable.add_bus_car);
		// holder.carNumber.setText(carlistEntity.getCarNumber());
		// holder.carBrand.setText(carlistEntity.getCarBrand());
		// holder.carFrameNumber.setText(carlistEntity.getCarFrameNumber());
		// holder.carEngineNumber.setText(carlistEntity.getCarEngineNumber());

		return convertView;
	}

	final class ViewHolder {
		private TextView carNumber, carBrand, carFrameNumber, carEngineNumber;
		private TextView car_brand;
		private String car_id, hud_sn;
		private ImageView carlistsmall_iv;
		private CircleImageView carlistimage;
	}
}
